<template>
	<view class="season">
		<custom-navi :show-home="false">选择营业日</custom-navi>
		<!-- <view class="">
			
		</view> -->
		<view class="season-date">
			<checkbox-group v-for="(item,index) in checkbox" :key='index' class="block" @change="CheckboxChange($event,index)">
				<view class="season-date-list">
					<checkbox :class="item.checked?'checked':''" :checked="item.checked?true:false" style="transform:scale(0.6)" :value="item.value"></checkbox><text>{{item.txt}}</text>
				</view>
			</checkbox-group>
		</view>
		<view class="btn">
		  <button @tap="handleSubmit">确认</button>
		</view>
	</view>
</template>

<script>
	export default {
		data () {
		  return {
		    checkbox: [{
				txt:'周日',
		    	value: '1',
		    	checked: false
		    }, {
				txt:'周一',
		    	value: '2',
		    	checked: false
		    }, {
				txt:'周二',
		    	value: '3',
		    	checked: false
		    }, {
				txt:'周三',
		    	value: '4',
		    	checked: false
		    }, {
				txt:'周四',
		    	value: '5',
		    	checked: false
		    }, {
				txt:'周五',
		    	value: '6',
		    	checked: false
		    }, {
				txt:'周六',
		    	value: '7',
		    	checked: false
		    }],
			week:[]
		  }
		},
		onLoad (option) {
			console.log(option.type)
			let time = option.type.split(",")
			for(var i=0;i<this.checkbox.length;i++){
				for(var j=0;j<time.length;j++){
					if(this.checkbox[i].value==time[j]){
						this.checkbox[i].checked=true
					}
				}
			}
			this.week=time
			console.log(this.week)
		},
		methods:{
			CheckboxChange(e,index) {
				var items = this.checkbox,
					values = e.detail.value;
					if(values[0]===items[index].value){
						this.checkbox[index].checked=true
						this.week.push(values[0])
					}else{
						this.checkbox[index].checked=false
						for(var i=0; i<this.week.length;i++){
							if(items[index].value===this.week[i]){
								this.week.splice(i,1)
							}
						}
					}
					console.log(this.week)
			},
			handleSubmit(){
				// console.log(this.week.join(','))
				// uni.navigateBack({
				//     url: '../timeSet/index?week='+this.week.join(',')
				// });
				uni.setStorageSync('week', this.week.join(','));
				// uni.setStorage({
				//     key: 'week',
				//     data: this.week.join(','),
				//     success: function () {
				//         console.log('success');
				//     }
				// });
				setTimeout(() => {
				  return this.$utils.common.navigateBack()
				}, 1000)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.season{
		&-date{
			width:100%;
			height:488rpx;
			padding: 32rpx;
			background:rgba(255,255,255,1);
			opacity:1;
			.block{
				margin-bottom: 10rpx;
			}
			&-list{
				text{
					font-size:28rpx;
					font-family:PingFang SC;
					font-weight:bold;
					color:rgba(80,80,80,1);
					opacity:1;
					margin-left: 20rpx;
				}
			}
		}
	}
	.btn {
	  position: fixed;
	  bottom: 116rpx;
	  width: 100vw;
	  display: flex;
	  justify-content: center;
	  button {
	    font-size: 34rpx;
	    font-family: PingFang SC;
	    font-weight: 500;
	    color: rgba(255, 255, 255, 1);
	    width: 686rpx;
	    height: 88rpx;
	    background: rgba(12, 212, 211, 1);
	    opacity: 1;
	    border-radius: 10rpx;
	  }
	}
</style>
